package kmp;

public class leetCode14_longestCommonPrefix {

    public String longestCommonPrefix(String[] strs) {
        if(strs == null || strs.length == 0) return null;
        String res = strs[0];
        for (String str : strs) {
            int j = 0;
            while (j < res.length() && j < str.length() && res.charAt(j) == str.charAt(j)){
                j++;
            }
            res = res.substring(0,j);
        }

        return res;
    }
}
